package com.itheima_04;

import java.lang.reflect.Field;

public class FieldTest {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
        Class clazz = Class.forName("com.itheima_04.Student");
        Field[] fields = clazz.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        System.out.println("---------------------------");
        Field name = clazz.getDeclaredField("name");
        Object o = clazz.newInstance();
        name.setAccessible(true);
        String name1 = (String) name.get(o);
        System.out.println(name1);
        System.out.println("---------------------------------");
        Field age = clazz.getField("age");
        Object o1 = clazz.newInstance();
        age.set(o1,10);
        System.out.println(o1);
    }

}
